package dao

import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile
import tool.Pojo.LongData

import javax.inject.Inject
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

/**
 * Created by yz on 2017/6/1.
 */
class DetailLongRnaDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends
  HasDatabaseConfigProvider[JdbcProfile] {

  import profile.api._

  type MyRow = DetailLongRnaRow
  val table = DetailLongRna

  def insert(longrnageneannotation: MyRow): Future[Unit] = db.run(table +=
    longrnageneannotation).map(_ => ())

  def insertAll(longrnageneannotation: Seq[MyRow]): Future[Unit] = db.run(table ++=
    longrnageneannotation).map(_ => ())

  def deleteAll(): Future[Unit] = db.run(table.delete).map(_ => ())

  def selectByGeneNames(names: Seq[String]) = {
    db.run(table.filter(_.geneName.inSetBind(names)).result)
  }

  def selectByGeneName(name: String) = {
    db.run(table.filter(_.geneName===name).result.head)
  }

  def selectAllGeneNames: Future[Seq[String]] = {
    db.run(table.map(_.geneName).distinct.result)
  }

  def selectAllSampleTypes: Future[Seq[String]] = {
    db.run(table.map(_.sampleType).distinct.result)
  }

  def selectHead10000 = {
    db.run(table.take(1000).result)
  }

}
